<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实战02-子父通信</title>

    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>

</head>
<body>
    
    <div id="app">
        <h1>Vue实例标题：{{title}}</h1>
        <hr><br>
        <!-- 
            此处注意：使用v-bind（即冒号）与不使用的区别 
            使用v-bind即绑定Vue实例中的data；
            不使用v-bind则将普通字符通过props传递给子组件。

        -->
        <!-- 
            @ 符号，即为v-on 
            : 符号，即为v-bind
         -->
        <cpn :cgies = 'categories' @doouterclick='vuouterclick'></cpn>
        <hr><br>
        模拟子tab页显示数据：{{mytabShowData.v}}
    </div> 

<template id="cpn">
    <div>
    <hr>
        <h2>这是Vue实例模版</h2>
    <hr>
    <button v-for='(item,index) in cgies' @click="innerClick(item)" > {{index}} - key:{{item.key}} => {{item.v}}</button>
    </div>
</template>
</body>
</html>

<script>

var app = new Vue({
  el: '#app',
  data: {
      title:'这是标题',
      pv01:'哈哈哈',
      pv02:'呵呵',
      categories:[
          {key:1,v:'足球'},
          {key:2,v:'懒球'},
          {key:3,v:'羽毛球'},
      ],
      mytabShowData:{key:-1 , v: ''}
  },
  methods:{
    vuouterclick(fromsubItem){
        console.log('Vue实例，获取到子组件emit: ',fromsubItem);
        this.mytabShowData.v = fromsubItem.v;
    }
  },
  components:{
      cpn:{
          template:'#cpn',
          props:{
            cgies:{
                type:Array
            }
          },
          methods:{
              innerClick(item){
                // console.log(item);
                this.$emit('doouterclick',item);
              }
          }
      }
  }
})
</script>